package com.spring.bucks.service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.spring.bucks.model.Coffee;
import com.spring.bucks.repository.CoffeeMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
@CacheConfig(cacheNames = "coffee")
public class CoffeeService extends ServiceImpl<CoffeeMapper,Coffee> {
    @Autowired
    private CoffeeMapper coffeeMapper;

    @CacheEvict
    public void reloadCoffee() {
    }

    /**
     * 查询时需要实现翻页
     * 查询时增加将结果缓存到 redis
     * @param pageNo
     * @param pageSize
     * @return
     */
    @Cacheable
    public Page findCoffeeList(Integer pageNo,Integer pageSize) {
        Page<Coffee> page = new Page<>(pageNo, pageSize);
        Page<Coffee> result = this.page(page);
        return result;
    }

    public Coffee findByName(String name) {
        return coffeeMapper.selectByName(name);
    }

    public List<Coffee> findByIds(String name,List<Integer> ids) {
        return coffeeMapper.selectByIds(name,ids);
    }
}
